package data;

import java.util.Calendar;
import java.util.GregorianCalendar;

import junit.framework.Assert;

import org.junit.Test;

import stalker.user.User;
import data.content.Content;
import data.content.ContentSentence;

public class DataTest {

  @Test
  public void testData() {
    User irvan, gogo;
    irvan = User.createUser("Irvan");
    gogo = User.createUser("Gogo");
    Content c = new ContentSentence("I like to move");
    
    Calendar before = new GregorianCalendar();
    Data di = new Data(irvan, c);
    Calendar after = new GregorianCalendar();    
    
    Assert.assertTrue("User:getCreationCalendar fail",
        di.getCreationCalendar().compareTo(before) >= 0);
    Assert.assertTrue("User:getCreationCalendar fail",
        di.getCreationCalendar().compareTo(after) <= 0);
    
    Data dg1 = new Data(gogo, c);
    Data dg2 = new Data(gogo, new ContentSentence("Are you handsome?"));
    Data dg3 = new Data(gogo, new ContentSentence("I like to move"));
    System.out.println(di);
    System.out.println(dg1);
    System.out.println(dg2);
    
    Assert.assertEquals("DataTest: getContent fails", 
        di.getContent(), c);
    Assert.assertEquals("DataTest: getContent fails", 
        dg3.getContent(), c);
    Assert.assertFalse("DataTest: getContent fails", 
        dg2.getContent().equals(c));
    Assert.assertEquals("DataTest: getCreator fails", 
        di.getCreator(), irvan);
    Assert.assertFalse("DataTest: getCreator fails", 
        di.getCreator().equals(gogo));
    Assert.assertTrue("DataTest: equals fails", 
        di.equals(di));
    Assert.assertFalse("DataTest: equals fails", 
        dg1.equals(di));
    Assert.assertFalse("DataTest: equals fails", 
        dg1.equals(dg2));
    Assert.assertFalse("DataTest: equals fails", 
        dg1.equals(null));
    Assert.assertFalse("DataTest: equals fails", 
        dg1.equals((Integer)5));
  }

  @Test(expected=AssertionError.class)
  public void testNullContent() {
    Data data = new Data(User.createUser("Ampas"), null);
    System.out.println(data);
  }
  
  @Test(expected=AssertionError.class)
  public void testNullUsername() {
    Data data = new Data(null, new ContentSentence("a"));
    System.out.println(data);
  }
  
  @Test(expected=AssertionError.class)
  public void testNullBoth() {
    Data data = new Data(null, null);
    System.out.println(data);
  }

}
